<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css">
</head>

<body class="childrenBody">
	<form class="layui-form layui-row changePwd" style="padding: 20px 20px 10px 20px;background-color: #fff;">
		<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
			<div class="layui-form-item">
				<label class="layui-form-label">账号</label>
				<div class="layui-input-block">
					<input type="text" value="" class="layui-input" id="account">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">旧密码</label>
				<div class="layui-input-block">
					<input type="password" value="" placeholder="请输入旧密码" lay-verify="oldPwd" id="oldPwd"
						class="layui-input pwd">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block">
					<input type="password" value="" placeholder="请输入新密码" lay-verify="newPwd" id="newPwd"
						class="layui-input pwd">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认密码</label>
				<div class="layui-input-block">
					<input type="password" value="" placeholder="请确认密码" lay-verify="confirmPwd" class="layui-input pwd">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button id="btn_submit" class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script>
		layui.use(['form', 'layer'], function () {
			var form = layui.form,
				$ = layui.jquery

			var cld = layui.data('currLoginInfo').data;
			$('#account').val(cld.account);

			form.verify({
				account: function (value, item) { //value：表单的值、item：表单的DOM对象
					if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
						return '帐号不能有特殊字符';
					}
					if (/(^\_)|(\__)|(\_+$)/.test(value)) {
						return '帐号首尾不能出现下划线\'_\'';
					}
					if (/^\d+\d+\d$/.test(value)) {
						return '帐号不能全为数字';
					}
				},
				oldPwd: [/[\S]$/, '旧密码不能为空'],
				newPwd: [/^[\S]{6,12}$/, '新密码必须6到12位，且不能出现空格'],
				confirmPwd: function (v) {
					if ($('#newPwd').val() != v)
						return '两次输入的密码不一致'
				}
			});

			//监听提交
			$('#btn_submit').click(function () {
				(async function () {
					let res = await ajaxAsync(baseUrl('admin'), {
						id: cld.id,
						newpwd: $('#newPwd').val(),
						pwd: $('#oldPwd').val(),
						account: $('#account').val(),
					}, 'PUT')
				})()
				return false;
			});

		});
	</script>
</body>

</html>